
    //获取操作人的姓名及ID
    var loginData=JSON.parse(web.readCookie("loginData"));
    var service_name = loginData.user.name;
    var service_id = loginData.user.user_ID;
   
    //从二级页面返回列表页面刷新
    function doSubmit(){
        $('#submitBtn').click();
    }
    // 查询功能
    $("#form-search").Validform({
        tiptype:2,
        callback:function(form){
            if($('#timemin').val()!=''&&$('#timemax').val()==''){
                layer.msg('结束时间不能为空！', {icon: 5,time:1000});
                return false;
            }
            if($('#timemin').val()==''&&$('#timemax').val()!=''){
                layer.msg('开始时间不能为空！', {icon: 5,time:1000});
                return false;
            }
            getList(1,'20')    // 默认倒序
            return false;
        }
    });
    //通过询价时间排序   并查询   向上倒序   向下正序
    var flag1=false;
    $('#sortByCreatedTime img').click(function(){
         console.log(flag1);
        if(flag1){
            $(this).attr('src','../../img/copyup.png');
            getList(1,"20");
        }
        else{
            $(this).attr('src','../../img/downorder.png');
            getList(1,"10");
        }
        flag1=!flag1;
     });
     // 通过询价数量排序   并查询
    var flag2=true;
     $('#sortByAllNumber img').click(function () {       
        if(flag2){
            $(this).attr('src','../../img/copyup.png');
            getList(1,"40");
        }
        else{
            $(this).attr('src','../../img/downorder.png');
            getList(1,"30");
        }
        flag2=!flag2;
     });

    //询价单状态下拉框 
    $('#inquiryStat2').change(function () {       
        var value2 = $(this).val();
        for (var i=0;i<crmCustomerIdOnearry.length;i++) {
            if(crmCustomerIdOnearry[i]=='10'){               
                if(value2=='00'){
                    $('#inquiry_status').val('1020');
                }else if(value2=='01'){
                    $('#inquiry_status').val('10');
                }else{
                    $('#inquiry_status').val('20');
                }
            }else if(crmCustomerIdOnearry[i]=='30'){
                if(value2=='00'){
                    $('#inquiry_status').val('3040');
                }else if(value2=='01'){
                    $('#inquiry_status').val('30');
                }else{
                    $('#inquiry_status').val('40');
                }
            }
        }
    });
    //地址
    discountdata(123);
    // 获取 页面搜索条件

//表格相关操作
$('#orderList').on("click",".inquiryOperate",function () {
    var rowData = $(this).attr('rowData').split(',');
    var inquiry_status = rowData[12];
    var inquiry_id = rowData[0];
    var back;
    var matcher_id = '', matching_name = '', fix_price_id = '', fix_price_name = '';
    var customer_id = rowData[17];
    var customer_name = rowData[2];
    var receiver_province = rowData[18]; //cityCode
    var platform = rowData[19];
    var member_id= rowData[20];   
    if(inquiry_status == '50'){       
        goNextPage('详情页信息','productDetailOffer.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
        return false;
    }else if(inquiry_status == '60'||inquiry_status == '70') {
        goNextPage('退回信息','productDetail.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
        
        return false;
    }else if(inquiry_status == '10'){
        back = '1';
        matcher_id = service_id;
        matching_name = service_name;
    }else if (inquiry_status == '20'){
        back = '0';
        matcher_id = service_id;
        matching_name = service_name;
    }else if(inquiry_status == '30'){
        back = '1';
        matcher_id = '';
        matching_name = '';
        fix_price_id = service_id;
        fix_price_name = service_name;
    } else if (inquiry_status == '40'){
        back = '0';
        matcher_id = '';
        matching_name = '';
        fix_price_id = service_id;
        fix_price_name = service_name;
    }else if(inquiry_status == '80'){        
        goNextPage('详情页信息','productDetailOffer.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
        return false;
    }
    var operParams = {
        "async": true,
        "crossDomain": true,
        "url": root.xunjiadan.InquiryOrderMatch,
        "method": "POST",
        "headers": {
            "Content-Type": "application/json"
        },
        "processData": false,
        "data": JSON.stringify({
            "inquiry_id":inquiry_id ,
            "back": back,
            "state": inquiry_status,
            "matcher_id": matcher_id,
            "matching_name": matching_name,
            "fix_price_id":fix_price_id,
            "fix_price_name":fix_price_name
        })
    }
    $.ajax(operParams).done(function (response) {
        if (response.code == '0') {
            if (inquiry_status == '10' || inquiry_status == '20') {
                goNextPage('待匹配','match.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
            } else if (inquiry_status == '30' || inquiry_status == '40') {
                goNextPage('待定价','fixPrice.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
            } else {

            }
        } else if (response.code == '60' || response.code == '70') {
            layer.msg('该询价单已失效，请刷新页面！', {icon: 5,time:1000});
        } else if(response.code == '10'||response.code == '30'){
            layer.msg('该询价单状态已经改变，请重新查询！', {icon: 5,time:1000});
        }  else { // 10或者20
            if (inquiry_status == '10' || inquiry_status == '20') {
                goNextPage('待匹配','match.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
            } else if (inquiry_status == '30' || inquiry_status == '40') {
                goNextPage('待定价','fixPrice.html?inquiry_id='+inquiry_id+'&inquiry_status='+inquiry_status+'&matcher_id='+matcher_id+'&matching_name='+matching_name+'&fix_price_id='+fix_price_id+'&fix_price_name='+fix_price_name+'&customer_id='+customer_id+'&customer_name='+customer_name+'&receiver_province='+receiver_province+'&platform='+platform+'&member_id='+member_id)
            } else {

            }           
        }
    });
});
function goNextPage(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
//点搜索之后查询数据列表
/*表格渲染*/
var table;   //table对象
var dataSource = [];
function orderList(data) {
   // dataSource.splice(0, dataSource.length);//清空数组
    dataSource.length=0;
    var datashu =data.startIndex+1;
    $.each(data.list, function (i, field) {
        var datashus = datashu++;        
        var rowData = new Array();
        rowData.push(field.inquiry_id);
        rowData.push(field.platform);
        if(field.customer_name){
            rowData.push(field.customer_name);
        }else{
            rowData.push(field.login_account);
        }
        rowData.push(field.linkman);
        rowData.push(field.receiver_province_name);
        rowData.push(field.created_time);
        rowData.push(field.all_number);
        rowData.push(field.exist_price_number);
        rowData.push(field.matching_name);
        rowData.push(field.matching_time);
        rowData.push(field.fix_price_name);
        rowData.push(field.fix_price_time);
        rowData.push(field.inquiry_status);
        rowData.push(field.inquiry_status);
        dataSource.push(rowData);
        rowData.push(field.matcher_id);
        rowData.push(field.fix_price_id);
        rowData.push(field.id);
        rowData.push(field.customer_id);
        rowData.push(field.receiver_city);     //仓库id -->城市code
        rowData.push(field.platform);               //平台普通 签约
        rowData.push(field.member_id);
        rowData.push(field.source);
        rowData.push(datashus);
        rowData.push(field.warehouse_code);
        rowData.push(field.belong_groupId);
        rowData.push(field.products);
    });
   
    initDataList(dataSource);
}

//询价状态码与相对应文案
var stateFormatObj = {
    '10':'待匹配', '20':'待匹配','30':'待定价','40':'待定价','50':'已报价','60':'已退回','70':'已撤销','80':'已下单'
}

//询价列表渲染
function initDataList(dataSource){
    var outHtml = '';   
    for(var i=0;i<dataSource.length;i++){
        var curData= dataSource[i]; 
        
        var platFormStr =  curData[1]=="10" ? "签约平台" : "普通平台";

        var inquiryStr = '';
        var productData = curData[25];
        var productStr = '';
        var curProLen = productData ? productData.length : 1;

        inquiryStr+= '<td width="115" rowspan="'+curProLen+'">'+isUndefined(curData[2])+'</td>'+
                     '<td width="70" rowspan="'+curProLen+'">'+isUndefined(curData[3])+'</td>'+
                     '<td width="70" rowspan="'+curProLen+'">'+isUndefined(curData[4])+'</td>'+
                     '<td width="70" rowspan="'+curProLen+'">'+isUndefined(curData[6])+'</td>'+
                     '<td width="70" rowspan="'+curProLen+'">'+isUndefined(curData[7])+'</td>'+
                     '<td width="70" rowspan="'+curProLen+'">'+isUndefined(curData[8])+'</td>'+
                     '<td width="100" rowspan="'+curProLen+'">'+timeIsDefault(curData[9])+'</td>'+
                     '<td width="70" rowspan="'+curProLen+'">'+isUndefined(curData[10])+'</td>'+
                     '<td width="100" rowspan="'+curProLen+'">'+timeIsDefault(curData[11])+'</td>'+
                     '<td width="100" rowspan="'+curProLen+'">'+platformCome(curData[21])+'</td>'+
                     '<td width="100" rowspan="'+curProLen+'"><span inquiry_status="'+curData[12]+'">'+stateFormatObj[curData[12]]+'</span>'+'</td>'+
                     '<td width="75" rowspan="'+curProLen+'">'+oprateHtml(curData)+'</td>';
                    

        var showMoreHtml = '';
        if(curProLen>3){
            showMoreHtml = '<div class="list_more " onclick="showMore(this);"><a href="javascript:void(0);">查询了<span id="list_length">'+curProLen+'</span>件商品  <span id="operText">更多</span><i class="icon"></i></a></div>' 
        }
        if(productData && productData.length>0){
            for(var j=0;j<productData.length;j++){
                var curPro = productData[j];
                var skuName = curPro.sku_code=='0'||curPro.sku_code=='' ? '' : curPro.sku_name;

                if(j!=0){
                    inquiryStr = '';
                }

                var isHideClass = '';
                if(j>=3){
                    isHideClass = 'moretr hide';
                }

                productStr +='<tr class="'+isHideClass+'">'+
                '<td width="75" rowspan="1">'+curPro.product_name+'</td>'+
                '<td width="135" rowspan="1">'+skuName+'<br/>'+curPro.sku_code+'</td>'+                   
                '<td width="135" rowspan="1">'+isProductError(curPro.product_depict)+'</td>'+  inquiryStr +
              '</tr>';                 
            }             
            
        }else{
            productStr +='<tr>'+
            '<td width="75" rowspan="1"></td>'+
            '<td width="135" rowspan="1"></td>'+                   
            '<td width="135" rowspan="1"></td>'+  inquiryStr +                 
          '</tr>';  
        }
        
        outHtml+= '<div class="orer_item"><div class="list_box list_over">'+
        '<div class="title">'+
        '<span>询价单号：'+isUndefined(curData[0])+'</span>'+
        '<span>询价时间：'+isUndefined(curData[5])+'</span>'+
        '<span>所属平台：'+platFormStr+'</span>'+                        
        '</div>'+
        '<table style="width:100%;" class="table table-border table-bg table-sort list_box_table"><tbody>'+productStr+'</tbody></table></div>'+showMoreHtml+'</div>';
    }

    $('#orderList').empty().append(outHtml);
}


// 为null或undefined时
function isUndefined(dt){
    var str = dt ? dt : '';
    return str;
}


//询价时间判断
function timeIsDefault(tm){
    var str = tm == '1000-01-01 00:00:00' ? '' : tm;
    return str;
}

//处理询价来源
function platformCome(plat){
    var str = plat == 10 ? 'PC' : 'APP';
    return str;
}

//操作栏渲染
function oprateHtml(curObj){    
    var organizationWarehouse =sessionStorage.getItem("organizationWarehouse")//子仓库
    var belongGroupIds = sessionStorage.getItem("companys")//销售归属权限串
    var warehouse_id=sessionStorage.getItem("regions")//主仓库
    var companys_ids=sessionStorage.getItem("companys")//客户归属
    var curState = curObj[13];
    var opeHtml = '';    
    if(curState == '10' || curState=='20' || curState=='30' || curState=='40'){
        var curText = curState=='10' || curState=='20' ? '匹配' : '定价';
        if(warehouse_id!="" || companys_ids!=""){
             //子仓库不为空或许子仓库不为空时
            var isHas = false;             
            var organizationWarehouseAll=organizationWarehouse.split(",");
            var warehouse_id=warehouse_id.split(",");
            var companys_idAll=companys_ids.split(",");

            var wareHouseArr = organizationWarehouseAll.concat(warehouse_id);

            if(wareHouseArr.indexOf(curObj[23]) >=0 || companys_idAll.indexOf(curObj[24])>=0){
                isHas = true;
            }            

            if(isHas){
                opeHtml = '<a  href="javascript:void(0);" inquiry_status="' + curObj[13] + '" rowData="' + curObj.slice(0,curObj.length-1) + '" class="inquiryOperate 105">'+curText+'</a>';    
            }else {                
                opeHtml= '<a style="color: #1476E5;"  class="105" onclick="chuli()">'+curText+'</a>';                
            }

        }else{            
            opeHtml = '<a style="color: #1476E5;"  class="105" onclick="chuli()">'+curText+'</a>';
        }
    }else{
        opeHtml = '<a  href="javascript:void(0);" inquiry_status="'+curObj[13]+'" rowData="'+curObj.slice(0,curObj.length-1)+'" class="inquiryOperate 105">查看</a>';
    }    
    return opeHtml;

}


//展示更多事件
function showMore(dom, length,status) {   
    var curDom = $(dom);
    var curTr = curDom.parents('.orer_item').find('.moretr');
    if(curTr.eq(0).hasClass('hide')){
        curTr.removeClass('hide');
        curDom.find('#operText').html('收起');
    }else{
        curTr.addClass('hide'); 
        curDom.find('#operText').html('更多');
    }
  
  }

function chuli() {
    $.Huimodalalert('暂无此处理权限！', 2000);
}
function getList(page_num,orderNum,aa){
    url =root.xunjiadan.getInquiryManagerList
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: url,
        cache: false,  //禁用缓存
        dataType: "json",
        data: JSON.stringify({
            "total":"",
            "totalPage":"",
            "pageNumber":page_num,
            "pageSize":10,
            "startIndex":"",
            "select_Manage":getParams(orderNum,aa),
        }),
        success: function (result) {
            sessionStorage.setItem("Instatus1",'')
            sessionStorage.setItem("Instatus2",'')
            console.log(result);
            orderList(result);
            $('.M-box3').pagination({
                 pageCount: result.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api){
                    $.ajax({
                        contentType: "application/json",
                        type: "POST",
                        url:root.xunjiadan.getInquiryManagerList,
                        cache: false,  //禁用缓存
                        dataType: "json",
                        data: JSON.stringify({
                            pageNumber: api.getCurrent(), //当前页码
                            pageSize: 10,//每页显示条数
                            startIndex:"",
                            select_Manage:getParams(orderNum,aa),
                        }),
                        success: function (result) {
                            orderList(result);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}
function discountdata (val) {
    if(val==123){
        //初始化 省
        var user_data = {
            level: '101',           
        }
        var succCallBack = function (data, status, response) {
            if(data.errorCode=="1"){
                var tab_data=data.list;
                if(tab_data==''){
                    cer+='<option value=""></option>'
                    $("#getArea").html(cer);
                }else{
                    var cer="<option value=''>请选择收货区域</option>"
                    for(var i=0; i<tab_data.length; i++){
                        cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                    }
                    $("#getArea").html(cer);
                }
            }
        };
        web.doAjax(root.orderInter.order_return_address,'post',user_data, succCallBack);
    }else if(val==1){
        //市
        var special=$('#getArea').val()
        if(special==""){
            var cer="<option value=''>请选择收货位置</option>"
            $("#getPlace").html(cer);
        }else {
            var user_data = {
                level: '102',               
                addressIdStr:special
            }
            var succCallBack = function (data, status, response) {
                if(data.errorCode=="1"){
                    var tab_data=data.list;
                    if(tab_data==''){
                        cer+='<option value=""></option>'
                        $("#getPlace").html(cer);
                    }else{
                        var cer="<option value=''>请选择收货位置</option>"
                        for(var i=0; i<tab_data.length; i++){
                            cer+='<option value="'+tab_data[i].code+'">'+tab_data[i].name+'</option>'
                        }
                        $("#getPlace").html(cer);
                    }
                }
            };
            web.doAjax(root.orderInter.order_return_address,'post',user_data, succCallBack);
        }
    }
}
function getParams(orderNum,aa){
    var created_time='';
    var all_number='';
    if(orderNum=='10'||orderNum=='20'){
        created_time=orderNum;
        all_number='';
    }else if(orderNum=='30'||orderNum=='40'){
        all_number = orderNum-20;
        created_time='';
    }else{
        all_number='';
        created_time='';
    }
    var created_time = created_time;
    var inquiry_id = $('#inquiry_id').val();
    var customer_name  = $('#customer_name').val();
    var inquiry_status = "";
    if(aa==1000){
        inquiry_status = "1020"
    }else if(aa==2000){
        inquiry_status = "3040"
    }else {
        inquiry_status =  $('#inquiry_status').val()
    }
    var statusLists=[]
    if(inquiry_status!=""){
        statusLists=[]
    }else {
        statusLists=crmCustomerIdOnearry
    }
    var start_time = $('#timemin').val();
    var end_time = $('#timemax').val();
    var matching_name = $('#matching_name').val();
    var fix_price_name = $('#fix_price_name').val();
    var receiver_province = $('#getArea').val();
    var linkman = $('#linkman').val();
    var all_number = all_number
    var platform = $('#platform').find("option:selected").val();
    var project_name = $('#project_name').val();
    var product_name = $('#product_name').val();
    return {
        "inquiry_id":inquiry_id,
        "customer_name":customer_name,
        "inquiry_status":inquiry_status,
        "statusList":statusLists,
        "start_time":start_time,
        "end_time":end_time,
        "matching_name":matching_name,
        "fix_price_name":fix_price_name,
        "receiver_province":receiver_province,
        "linkman":linkman,
        "created_time":created_time,
        "all_number":all_number,
        "platform":platform,
        "inquiry_name":project_name,
        "product_name":product_name,
        "source":$("#source").val(),
        warehouseIds:sessionStorage.getItem("regions"),//仓库权限串
        belongGroupIds:sessionStorage.getItem("companys"),//销售归属权限串
        salesManagerIds:sessionStorage.getItem("personnels"),//销售经理权限串
        orgWareHouseId:sessionStorage.getItem("organizationWarehouse"),//销售经理权限串
    }
}





    //交易状态
    var placeholder02html =[];//存放多选时的html
    var placeholder02htmlinit =[];
    var crmCustomerIdOnearry =[];//存放多选时的crmCustomerid
    var spanhtml = '';
    var crmCustomerIdOne='';
    $(".ulbox").css('display','none');
    /*点击 项目 显示下拉 选项,其中全选全不选，要做传值的处理*/
    $(".dataval,.icon_arrow").on('click',function (e) {
        $(this).parent().children(".icon_arrow").toggleClass("icon_arrow_down");
        if($('.ulbox').css("display") == "none"){
            $('.ulbox').show();
            if($(".placeholder02").find(".all-radius")&&$(".placeholder02").find(".all-radius").html()=="全部"){
                $(".placeholder02").html("")

            }
        }else{
            $(".ulbox").hide();
            if ($(".placeholder02").html()==""){
                $(".placeholder02").html('<span class="all-radius">全部</span>')
            }
        }
        /*------------------8.24 如果已经有选择过的--------------------*/
        var initcustomerId =[];
        placeholder02htmlinit=[]
        $.each($(".lidata"),function (index,itm) {

            initcustomerId.push($(itm).attr('crmCustomerId'))
            placeholder02htmlinit.push($(itm).attr('crmCustomername'))
        })
        if(crmCustomerIdOnearry.length >0){
            function isArray(str){
                return Object.prototype.toString.call(str) == "[object Array]";
            }
            if(isArray(crmCustomerIdOnearry)){
                crmCustomerIdOnearry= [crmCustomerIdOnearry].join().split(',');
            }else{
                crmCustomerIdOnearry= [crmCustomerIdOnearry].join().split(',');
            }
            $.each($(".lidata"),function (index,itm) {
                $.each(crmCustomerIdOnearry,function (i,item) {
                    $.each(initcustomerId,function (j,ite) {
                        if(item == ite){
                            if($("itm").attr('crmcustomerid')==item){
                                $(".lidata").find('.evetyipt').prop('checked',true);
                            }
                        }
                    })
                })
            })

        }
        e.stopPropagation();
    });
    //点击下拉中的文字可勾选
  /*  var checkednum=0;
    var htmlspan='';
    $(".ulbox").on('click','li.lidata',function (e) {
        e.stopPropagation();
        if($(this).find('input')){
            if($(this).find('input').prop('checked') == false){
                $(this).find('input').prop('checked',true);//选中
                checkednum ++;
                spanhtml=$(this).find('input').next().html();
                placeholder02html.push(spanhtml);
                crmCustomerIdOne = $(this).attr('crmCustomerId');
                crmCustomerIdOnearry.push(crmCustomerIdOne);
                $.each(placeholder02html,function(i,item){
                    htmlspan = '<span>'+item+'</span>'
                });
                $(".placeholder02").append(htmlspan);
                console.log(checkednum)
                if($(".ulbox").find('input.evetyipt').length == checkednum ){
                    $(".checkboxall").prev().prop('checked',true);
                }

                //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
                onenameadd()
            }else{
                checkednum --;
                $(this).find('input').prop('checked',false);
                var checkfalsehtml =  $(this).find('input').next().html();
                var tt =$(this).attr('crmcustomerId');
                for (var i=0;i<crmCustomerIdOnearry.length;i++){
                    if(crmCustomerIdOnearry[i] == tt){
                        crmCustomerIdOnearry.splice(crmCustomerIdOnearry.indexOf(tt),1);
                    }
                }
                var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
                $.each(iptspandata,function (i,item) {
                    if($(item).html() == checkfalsehtml){
                        $(item).html('')
                        $(item).remove();
                    }
                });
                placeholder02html.splice($(this).next().html(),1);
                if($(".ulbox").find('input.evetyipt').length != checkednum){
                    $(".checkboxall").prev().prop('checked',false);
                }
                onename();
            }
            console.log("111111111111111wwwwwwwwwwwwwwwwwwww")
            //第二个下拉框展示
            if(crmCustomerIdOnearry.indexOf("1020")>-1 || crmCustomerIdOnearry.indexOf("3040")>-1){
                $('#inquiryStat2').show()
            }else {
                $('#inquiryStat2').hide()
            }
        }
    });*/
    var checkednum=0;
    //当点击下拉数据时 回显在input里面
    var htmlspan='';
    $(".ulbox").on('click','input.evetyipt',function (e) {
        if($(".placeholder02").find(".all-radius")&&$(".placeholder02").find(".all-radius").html()=="全部"){
            $(".placeholder02").html("")

        }
        e.stopPropagation();
        if($(this).prop('checked')){
            $(this).prop('checked',true);//选中
            checkednum ++;
            spanhtml=$(this).next().html();
            placeholder02html.push(spanhtml);
            crmCustomerIdOne = $(this).parent().attr('crmCustomerId');
            var crmCustomerIdOnearr= crmCustomerIdOne.split(",")
            for (var h=0;h<crmCustomerIdOnearr.length;h++){
                crmCustomerIdOnearry.push(crmCustomerIdOnearr[h]);
            }

            console.log(crmCustomerIdOnearry)
            $.each(placeholder02html,function(i,item){
                htmlspan = '<span>'+item+'</span>'
            })
            $(".placeholder02").append(htmlspan);
            console.log(checkednum)
            if($(".ulbox").find('input.evetyipt').length == checkednum){
                $(".checkboxall").prev().prop('checked',true);
            }
            //全选反选时会用
            if (checkednum==0) {
            $(".checkboxall").prev().prop('checked',true);

            }
            //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
            onenameadd()
        }else{
            checkednum --;
            $(this).prop('checked',false);
            var checkfalsehtml =  $(this).next().html();
            var tt =$(this).parent().attr('crmCustomerId');
            var crmCustomerIdOnett= tt.split(",")
            for (var i=0;i<crmCustomerIdOnearry.length;i++){
                for (var d=0;d<crmCustomerIdOnett.length;d++) {
                    if (crmCustomerIdOnearry[i] == crmCustomerIdOnett[d]) {
                        crmCustomerIdOnearry.splice(crmCustomerIdOnearry.indexOf(crmCustomerIdOnett[d]), 1);
                    }
                }
            }
            var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
            $.each(iptspandata,function (i,item) {
                if($(item).html() == checkfalsehtml){
                    $(item).html('');
                    $(item).remove();
                }
            });
            placeholder02html.splice($(this).next().html(),1);
            if($(".ulbox").find('input.evetyipt').length != checkednum){
                $(".checkboxall").prev().prop('checked',false);
            }
            onename();
        }


       //状态第二个下拉框显示
        console.log(crmCustomerIdOnearry)
        if(crmCustomerIdOnearry!=""){
            if(crmCustomerIdOnearry.indexOf("10")>-1 && crmCustomerIdOnearry.indexOf("30")>-1){
                $('#inquiryStat2').hide()
                $('#inquiry_status').val("")
            }else if(crmCustomerIdOnearry.indexOf("10")>-1 || crmCustomerIdOnearry.indexOf("30")>-1){
                $('#inquiryStat2').show()
                console.log($("#inquiryStat2").val())
                if(crmCustomerIdOnearry.indexOf("10")>-1){
                    if($("#inquiryStat2").val()=='00'){
                        $('#inquiry_status').val('1020');
                    }else if($("#inquiryStat2").val()=='01'){
                        $('#inquiry_status').val('10');
                    }else{
                        $('#inquiry_status').val('20');
                    }

                }
                if(crmCustomerIdOnearry.indexOf("30")>-1){
                    if($("#inquiryStat2").val()=='00'){
                        $('#inquiry_status').val('3040');
                    }else if($("#inquiryStat2").val()=='01'){
                        $('#inquiry_status').val('30');
                    }else{
                        $('#inquiry_status').val('40');
                    }

                }
            }
            if(crmCustomerIdOnearry.indexOf("50")>-1 || crmCustomerIdOnearry.indexOf("60")>-1|| crmCustomerIdOnearry.indexOf("70")>-1){
                $('#inquiryStat2').hide()
                $('#inquiry_status').val("")
            }
        }else {
            $('#inquiryStat2').hide()
            $('#inquiry_status').val("")
        }



    });
    //可点击空白处
    $(document).click(function() {
        $(".ulbox").css('display','none');
        if ($(".placeholder02").html()==""){
            $(".placeholder02").html('<span class="all-radius">全部</span>')
        }
    });
    function onenameadd(){
        //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
        if(crmCustomerIdOnearry.length == 1){
            $(".placeholder02 span").css('max-width','none');
            $(".placeholder02 span").attr('title',$(".placeholder02 span").html());
        }else{
            $(".placeholder02 span").css('max-width','48px');
        }
    }
    function onename(){
        //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
        if(crmCustomerIdOnearry.length == 1){
            $(".placeholder02 span").css('max-width','none');
            $(".placeholder02 span").attr('title',$(".placeholder02 span").html());
        }
    }

    /*点击全选 联动 传值*/
    var ulboxli = $(".ulbox").find('li');
    $(".checkboxall").parent().on('click','input',function (e) {
        e.stopPropagation();
        if($(this).prop('checked')){//全选
            $(this).prop('checked',true);
            ulboxli.find('input').prop('checked',true);
            $(".placeholder02").html("")
            placeholder02html =placeholder02htmlinit;
            var htmlspan='';
            $.each(placeholder02html,function(i,item){
                htmlspan += '<span>'+item+'</span>'
            });
            $(".placeholder02").append(htmlspan);
            var crmCustomerIds=$(this).attr('crmCustomerId')
            crmCustomerIdOnearry=crmCustomerIds.split(",")
            $('#inquiryStat2').hide()
            $('#inquiry_status').val("")
        }else{//全不选
            $(this).prop('checked',false);
            ulboxli.find('input').prop('checked',false);
            crmCustomerIdOnearry=[];
            placeholder02html=[];
            $(".placeholder02").html('');
            $('#inquiryStat2').hide()
            $('#inquiry_status').val("")
        }
    });
    $(".ulbox").on('click','.checkboxall',function (e) {
        e.stopPropagation();
        if(  $(this).parent().find('input').prop('checked') == false){//全选
            $(this).parent().find('input').prop('checked',true);
            ulboxli.find('input').prop('checked',true);
            placeholder02html =placeholder02htmlinit;
            var htmlspan='';
            $.each(placeholder02html,function(i,item){
                htmlspan += '<span>'+item+'</span>'
            });
            $(".placeholder02").append(htmlspan);
            $('#inquiryStat2').hide()
            $('#inquiry_status').val("")
        }else{//全不选
            $(this).parent().find('input').prop('checked',false);
            ulboxli.find('input').prop('checked',false);
            crmCustomerIdOnearry=[];
            placeholder02html=[];
            $(".placeholder02").html('');
            $('#inquiryStat2').hide()
            $('#inquiry_status').val("")
        }
    })

    //弹框跳转
    var Instatus1= sessionStorage.getItem("Instatus1")//待匹配
    var Instatus2= sessionStorage.getItem("Instatus2")//待定价
    if(Instatus1==1020){
        crmCustomerIdOnearry=[]
        crmCustomerIdOnearry.push(10)
        placeholder02html.push("待匹配")
        $('#inquiryStat2').show()
        var htmlspan=""
        $.each(placeholder02html,function(i,item){
            htmlspan += '<span>'+item+'</span>'
        });
        $(".placeholder02").html(htmlspan);
        $(".ulbox").find('input.evetyipt')[0].checked=true
        getList(1,20,1000)
    }
    if(Instatus2==3040){
        crmCustomerIdOnearry=[]
        crmCustomerIdOnearry.push(30)
        placeholder02html.push("待定价")
        $('#inquiryStat2').show()
        var htmlspan=""
        $.each(placeholder02html,function(i,item){
            htmlspan += '<span>'+item+'</span>'
        });
        $(".placeholder02").html(htmlspan);
        $(".ulbox").find('input.evetyipt')[1].checked=true
        getList(1,20,2000)
    }
    //重置
    function ordersta() {
        $(".kild").val("");
        $(".Validform_checktip").hide();
        crmCustomerIdOnearry=[];
        placeholder02html=[];
        $(".placeholder02").html("");
        $('#inquiryStat2').hide();
        $('#inquiry_status').val('');  
    }